package com.example.cloud.api;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.cloud.domain.model.user.UserDO;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 为Service和Feign-Consumer提供API
 *
 * @author tongyufu
 */
@RequestMapping("/user")
public interface UserApi {

    /**
     * RequestParam传参
     *
     * @param id id
     * @return 用户信息
     */
    @ApiOperation(value = "查询指定ID用户", notes = "")
    @ApiImplicitParam(name = "id", value = "用户ID", paramType = "path", required = true, dataType = "Long")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    UserDO getUserById(@PathVariable("id") Integer id);

    /**
     * RequestHeader传参
     *
     * @param id id
     * @param name 中文有乱码
     * @return 用户信息
     */
    @ApiOperation("查询指定用户（通过header传参）")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "用户姓名", required = true, dataType = "String") })
    @RequestMapping(value = "header", method = RequestMethod.GET)
    UserDO getUser(@RequestHeader("id") Integer id, @RequestHeader("name") String name);

    /**
     * RequestBody传参
     *
     * @param userInfo 中文不会乱码
     * @return 用户信息
     */
    @ApiOperation("查询指定用户（通过RequestBody传参）")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "用户姓名", required = true, dataType = "String") })
    @RequestMapping(value = "body", method = RequestMethod.POST)
    UserDO getUser(@RequestBody UserDO userInfo);
}
